package com.market.manage.mapper;

import com.market.manage.po.Users;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PatchMapping;

import java.util.List;

/**
 * 用户表的操作
 */
@Repository
public interface UsersMapper {
    @Select("SELECT * FROM USERS WHERE ID=#{0}")
    Users selUserById(Long id);

    @Select("SELECT THUMB FROM USERS WHERE ID=#{0}")
    String selThumbById(Long id);

    @Select("SELECT NAME FROM USERS WHERE ID=#{0}")
    String selNameById(Long id);

    @Select("SELECT EMAIL FROM USERS WHERE ID=#{0}")
    String selById(Long id);

    @Select("SELECT * FROM USERS WHERE USERNAME=#{username} AND PASSWORD=#{password}")
    Users selUser(Users users);

    List<Users> selUsers(@Param("role") String role, @Param("name") String name, @Param("pageIndex") Long pageIndex, @Param("pageSize") Long pageSize);

    @Select("SELECT COUNT(ID) FROM USERS")
    Long countUsers();

    @Delete("DELETE FROM USERS WHERE ID=#{0}")
    int delete(Long id);

    @Select("SELECT * FROM USERS")
    List<Users> getAllUsers();

    int updUser(Users user);


    @Insert("INSERT INTO USERS VALUES(#{id},#{username},#{password},#{name},#{tel},#{email},#{rid},#{date},#{thumb})")
    int addUser(Users user);

    @Update("UPDATE USERS SET PASSWORD={password} WHERE ID=#{id}")
    int updPass(@Param("id") Long id, @Param("password") String password);

    @Update("UPDATE USERS SET PASSWORD=#{password} WHERE USERNAME=#{username}")
    int updaPass(@Param("username") String username, @Param("password") String password);

    @Select("SELECT * FROM USERS")
    List<Users> selAll();

    @Select("SELECT RID FROM USERS WHERE ID=#{0}")
    Long check(Long id);

    @Select("SELECT * FROM USERS WHERE USERNAME=#{0}")
    Users getUserByUsername(String username);
}
